package com.dailyblue.java.thread.作业;

// 售票问题
public class DemoD {

    private Integer ticket = 1; // 票号
    private static final Integer ALL_TICKET = 100; // 总票数

    public synchronized boolean 售票() {
        String name = Thread.currentThread().getName();
        if (ticket == ALL_TICKET + 1) {
            System.out.println("对不起，没票了!");
            return false;
        }
        System.out.println(name + "购买了：" + ticket + "号票");
        ticket++;
        return true;
    }
}
